package com.example.demo4.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo4.Dao.EmpDao;
import com.example.demo4.Service.EmpService;
import com.example.demo4.entity.Emp;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class EmpServiceImpl implements EmpService {
    @Resource
    private EmpDao empDao;

    @Override
    public Page<Emp> findAll(Integer pageIndex, String name) {
        LambdaQueryWrapper<Emp> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(name!=null,Emp::getName,name);

        return empDao.selectPage(new Page<Emp>(pageIndex,2),lambdaQueryWrapper);
    }

    @Override
    public void save(Emp emp) {
        empDao.insert(emp);
    }

    @Override
    public void removeById(Integer id) {
    empDao.deleteById(id);
    }

    @Override
    public Emp getById(Integer id) {
        return empDao.selectById(id);
    }

    @Override
    public void updateById(Emp emp) {
        empDao.updateById(emp);
    }

}




















